package com.controller;

import com.pojo.Page;
import com.pojo.Wages;
import com.service.WagesService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/wages")
public class WagesController {
    @Resource
    private WagesService service;
    @RequestMapping("/queryAll")
    @ResponseBody
    public Page queryAll(int pageIndex){
        Page page = new Page(5,pageIndex);
        List<Wages> list = service.queryWages(page.getStartIndex(),page.getEndIndex());
        int row=service.countAll();
        page.setResult(list,row);
        return page;
    }
    @RequestMapping("/queryby")
    @ResponseBody
    public Page queryby(int pageIndex,String userName,String deptName,String jobName,int start,int end){
        Page page = new Page(5,pageIndex);
        List<Wages> list = service.queryby(page.getStartIndex(),page.getEndIndex(),userName,deptName,jobName,start,end);
        int row=service.countAll();
        page.setResult(list,row);
        return page;
    }
    @RequestMapping("/update")
    @ResponseBody
    public String update(Integer wid, Integer wagescount){
        int result = service.updateWages(wid, wagescount);
        if (result > 0) {
            return "{\"fig\":\"success\"}";
        }
        else{
            return "{\"fig\":\"error\"}";

        }
    }
    @RequestMapping("/querybyid")
    @ResponseBody
    public Wages querybyid(int wid){
        Wages wages = service.queryWagesByID(wid);
        return wages;
    }
    @RequestMapping("/querybyname")
    @ResponseBody
    public Wages querybyname(String name){
        Wages wages = service.queryByName(name);
        return wages;
    }
    @RequestMapping("/querybyname2")
    @ResponseBody
    public List<Wages> querybyname2(String name){
        List<Wages> list = service.queryByName2(name);
        return list;
    }
    @RequestMapping("/addWages")
    @ResponseBody
    public String addwages(@RequestBody Wages wages){
        int result = service.addWages(wages);
        if (result > 0) {
            return "{\"fig\":\"success\"}";
        }
        else{
            return "{\"fig\":\"error\"}";

        }
    }
}
